package com.haihui.platform.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.haihui.platform.entity.SysAdUserInfo;

public class SysFilter implements Filter{

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)req;
		HttpServletResponse response = (HttpServletResponse)res;
		SysAdUserInfo user = (SysAdUserInfo)request.getSession().getAttribute("user");
		if(user == null){
			String uri = request.getRequestURI();
			if(uri.endsWith(".js") || uri.endsWith(".css") || uri.endsWith(".jpg") || uri.endsWith(".eot") || 
				uri.endsWith(".svg") || uri.endsWith(".ttf") || uri.endsWith(".woff") || uri.endsWith(".woff2") || 
				uri.endsWith(".ico") || uri.endsWith(".png") || uri.endsWith(".otf") || uri.endsWith(".png") || uri.endsWith(".psd") ||
				uri.endsWith("login.html") || uri.endsWith("/login")){
				chain.doFilter(request, response);
			}else{
				response.sendRedirect("/pybz/login.html");
			}
		}else{
			chain.doFilter(request, response);
		}
	}

	@Override
	public void destroy() {
		
	}

}
